﻿<cfscript>
/** 
* ORM TeacherTimeTable
* 
* @hint "Hibernate persistenter t_teacher_timetable. 教师排课时间占用情况表" 
* 
*/ 

component 
	displayname="public.service.orm.senate.TeacherTimeTable" 
	output=false 
	persistent=true 
	selectBeforeUpdate=true dynamicInsert=true dynamicUpdate=true 
	cacheuse="Transactional" 
	entityname="TeacherTimeTable" 
	table="t_teacher_timetable"
	{

	property type="string" name="TeacherTimeID" column="teachertime_id" fieldtype="id" generator="assigned" hint="教师上课时间编号";

	property type="string" name="TimeIndex" column="tidx" hint="上课时间序列";
	property type="string" name="WeekIndex" column="widx" hint="周次序列";

	property type="string" name="WeekDay" column="wdidx" hint="星期几";
	property type="numeric" name="CellStart" column="cellidx" hint="起点节次";
	property type="numeric" name="CellLength" column="cellrelay" hint="使用节次长度";

	property type="string" name="TaskClassRoom" column="taskclsroom" hint="上课地点";
	property type="string" name="TaskClassTime" column="tasktime" hint="上课时间";

	property type="string" name="TaskID" column="task_id" hint="教学任务号";
	property type="string" name="TaskType" column="task_type" hint="教学任务类别";
	property type="string" name="TaskWeek" column="task_week" hint="上课周次";

	property name="Term" fieldtype="many-to-one" fkcolumn="term_id" cfc="Term"  hint="学期";
	property name="Teacher" fieldtype="many-to-one" fkcolumn="tch_id" cfc="Teacher"  hint="教师";
	property name="Course" fieldtype="many-to-one" fkcolumn="cid" cfc="Course"  hint="课程";

	/**
	* @hint "生成排课时间序号"
	* 
	* @Term "学期"
	* @Teacher "教师"
	*/
	public string function getTimeIDX( required Term, required Teacher ) output=false {
		
		/* 
			排课时间序号规则 3位代码
		*/
		var nextID = numberFormat(1, "0__");
		
		var checkArray = ORMExecuteQuery("select TimeIndex from TeacherTimeTable 
											where 
											Term = :term and Teacher = :teacher 
											order by TimeIndex desc", {term=arguments.Term, teacher=arguments.Teacher}, { maxResults=1 });
		if (arrayLen(checkArray)) {
			/* 创建一个追加id */
			nextID = numberFormat((checkArray[1] + 1), "0__");
		}

		return nextID;
		
	}
	
	/**
	* @hint "自定义主键规则"
	* 
	* @Term "学期"
	* @Teacher "教师"
	* @TimeIndex "上课时间序列"
	*/
	public string function getID( required Term, required Teacher, required string TimeIndex ) output=false {
		
		var nextID = arguments.Term.getTermID() & "," & arguments.Teacher.getTeacherID() & "," & arguments.TimeIndex;

		/* 
			主键生成规则 
			
			教师上课时间编号18位 3位学期代码 , 10位教师职工号 , 3位时间序号

			Unique: TERM_ID, TCH_ID, TIDX
		*/
		return nextID;
	}
	
}

</cfscript>